home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / object / obj_plot.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  103 lines

  1. ;-------------------------------------------------------------
  2. ; This procedure file defines the procedure obj_plot, which is
  3. ; used as an example in Chapter 9 of _Objects and Object Graphics_.
  4. ;-------------------------------------------------------------
  5.  
  6. FUNCTION NORM_COORD, range
  7.  
  8. ; This function takes a range vector [min, max] as contained
  9. ; in the [XYZ]RANGE property of an object and converts it to
  10. ; a scaling vector (suitable for the [XYZ]COORD_CONV property)
  11. ; that scales the object to fit in the range [0,1].
  12.  
  13. scale = [-range[0]/(range[1]-range[0]), 1/(range[1]-range[0])]
  14.  
  15. RETURN, scale
  16.  
  17. END
  18.  
  19. ;-------------------------------------------------------------
  20.  
  21. PRO obj_plot, data, VIEW=myview, MODEL=mymodel, WINDOW=mywindow, $
  22.               CONTAINER=mycontainer, XAXIS=myxaxis, YAXIS=myyaxis, $
  23.           PLOT=myplot, _extra=e
  24.  
  25. ; If no data provided, create some default data.
  26. IF (N_ELEMENTS(data) EQ 0) THEN data = randomu(seed,100)
  27.  
  28. ; Create Container, Window, View, and Model objects.
  29.  
  30. mycontainer = OBJ_NEW('IDL_Container')
  31. mywindow = OBJ_NEW('IDLgrWindow')
  32. myview = OBJ_NEW('IDLgrView')
  33. mymodel = OBJ_NEW('IDLgrModel')
  34.  
  35. ; Create a font object.
  36.  
  37. myfont = OBJ_NEW('IDLgrFont', 'times')
  38.  
  39. ; Create a plot object using data specified at the command line.
  40.  
  41. myplot = OBJ_NEW('IDLgrPlot', data, COLOR=[200,100,200])
  42.  
  43. ; Pass any extra keywords to obj_plot to the SetProperty method of the
  44. ; plot object.
  45.  
  46. myplot ->SetProperty, _extra=e
  47.  
  48. ; Retrieve the data ranges from the plot object, and convert to
  49. ; normalized coordinates using the norm_coord function we created.
  50.  
  51. myplot -> GetProperty, XRANGE=xr, YRANGE=yr
  52. myplot->SetProperty, XCOORD_CONV=norm_coord(xr), YCOORD_CONV=norm_coord(yr)
  53.  
  54. ; Create X and Y axis objects with appropriate ranges, and convert
  55. ; to normalized coordinates. Set the tick lengths to 5% of the data
  56. ; range (which is now nomralized to 0.0-1.0).
  57.  
  58. myxaxis = OBJ_NEW('IDLgrAxis', 0, RANGE=[xr[0], xr[1]])
  59. myxaxis -> SetProperty, XCOORD_CONV=norm_coord(xr)
  60. myyaxis = OBJ_NEW('IDLgrAxis', 1, RANGE=[yr[0], yr[1]])
  61. myyaxis -> SetProperty, YCOORD_CONV=norm_coord(yr)
  62. myxaxis -> SetProperty, TICKLEN=0.05
  63. myyaxis -> SetProperty, TICKLEN=0.05
  64.  
  65. ; Add the model object to the view object, and the plot and axis objects
  66. ; to the model object.
  67.  
  68. myview -> Add, mymodel
  69. mymodel -> Add, myplot
  70. mymodel -> Add, myxaxis
  71. mymodel -> Add, myyaxis
  72.  
  73. ; Set an appropriate viewplane rectangle and zclip region for the view.
  74.  
  75. SET_VIEW, myview, mywindow
  76.  
  77. ; Add a Title to the X axis.
  78.  
  79. xtext = OBJ_NEW('IDLgrText', 'X Title', FONT=myfont)
  80. myxaxis -> SetProperty, TITLE=xtext
  81.  
  82. ; Add all objects to the container object. Destroying the container
  83. ; will destroy all of its contents.
  84.  
  85. mycontainer -> Add, mywindow
  86. mycontainer -> Add, myview
  87. mycontainer -> Add, myfont
  88. mycontainer -> Add, xtext
  89.  
  90. ; Draw the object tree.
  91.  
  92. mywindow -> Draw, myview
  93.  
  94. val=''
  95. READ, val, PROMP='Press <Return> to Redraw.'
  96. mywindow -> Draw, myview
  97.  
  98. READ, val, PROMP='Destroy objects? (y/n) [y]: '
  99. IF (STRPOS(STRUPCASE(val),'N') EQ -1) THEN $
  100.     OBJ_DESTROY, mycontainer
  101.  
  102. END
  103.